CREATE DATABASE MenusHunter
GO

USE MenusHunter
GO

CREATE TABLE Accounts
(
	Id int identity primary key,
	Email varchar(255) unique not null,
	[Password] varchar(255) not null,
	FullName		nvarchar(255) not null,
	Avatar	varchar(200) default 'http://www.mhunter.somee.com/images/no_avatar.png',
	Gender	bit default 1,
	Birthday date,
	[Address] nvarchar(255),
	Phone varchar(20),
	AccessToken	varchar(255),	
	DateCreate	date default getdate(),
	[Type] int default 1,	
	[Status] int default 0
)
GO

CREATE TABLE Restaurants
(
	Id int identity primary key,
	AccountId int,
	Name	nvarchar(255) not null,
	[Description] varchar(MAX),
	Photo varchar(255),
	Latitude	float not null,
	Longtitude	float not null,
	[Address] nvarchar(255),
	Phone varchar(20),
	DateCreate Date default getdate(),
	IsFeature bit default 0,
	[Status] int default 0
)
GO

ALTER TABLE Restaurants ADD CONSTRAINT FK_RESTAURANT_ACCOUNT FOREIGN KEY (AccountId) REFERENCES Accounts(Id)

CREATE TABLE Photos
(
	Id int identity primary key,
	RestaurantId int not null,
	Url	varchar(255),
	UrlThumb varchar(255),
	[Decription] nvarchar(MAX),
	DateCreate date default getdate(),	
	[Status] int default 0
)
GO


ALTER TABLE Photos ADD CONSTRAINT FK_PHOTO_RESTAURANT FOREIGN KEY (RestaurantId) REFERENCES Restaurants(Id)
GO

CREATE TABLE Foods
(
	Id int identity primary key,
	RestaurantId int,
	Name nvarchar(255) not null,
	[Description] nvarchar(255),
	ImgesUrl varchar(255) default 'http://www.mhunter.somee.com/images/no_image.png',
	Price	money default 0,
	Currency	nvarchar(20) default 'VNĐ',
	DateCreate Date default getdate(),
	[Status]	int default 0
)
GO

ALTER TABLE Foods ADD CONSTRAINT FK_FOOD_RESTAURANT FOREIGN KEY (RestaurantId) REFERENCES Restaurants(Id)
GO

















